/*     */ package com.zimbra.cs.ldap.unboundid;
/*     */ 
/*     */ import com.unboundid.asn1.ASN1OctetString;
/*     */ import com.unboundid.ldap.sdk.Attribute;
/*     */ import com.unboundid.ldap.sdk.Entry;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.ldap.LdapException;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZLdapElement.ZLdapElementDebugListener;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ import java.util.Collection;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class UBIDMutableEntry
/*     */   extends ZMutableEntry
/*     */ {
/*     */   private Entry entry;
/*     */   
/*     */   public UBIDMutableEntry()
/*     */   {
/*  42 */     this.entry = new Entry("");
/*     */   }
/*     */   
/*     */   public void debug(ZLdapElement.ZLdapElementDebugListener debugListener)
/*     */   {
/*  47 */     print(debugListener, this.entry.toString());
/*     */   }
/*     */   
/*     */   Entry getNative() {
/*  51 */     return this.entry;
/*     */   }
/*     */   
/*     */   public ZAttributes getAttributes()
/*     */   {
/*  56 */     return new UBIDAttributes(this.entry);
/*     */   }
/*     */   
/*     */   public String getDN()
/*     */   {
/*  61 */     return this.entry.getDN();
/*     */   }
/*     */   
/*     */   public void setAttr(String attrName, String value)
/*     */   {
/*  66 */     if (hasAttribute(attrName)) {
/*  67 */       this.entry.removeAttribute(attrName);
/*     */     }
/*  69 */     this.entry.addAttribute(attrName, value);
/*     */   }
/*     */   
/*     */   public void addAttr(String attrName, Set<String> values)
/*     */   {
/*  74 */     for (String value : values) {
/*  75 */       this.entry.addAttribute(attrName, value);
/*     */     }
/*     */   }
/*     */   
/*     */   public void addAttr(String attrName, String value)
/*     */   {
/*  81 */     this.entry.addAttribute(attrName, value);
/*     */   }
/*     */   
/*     */   public String getAttrString(String attrName) throws LdapException
/*     */   {
/*  86 */     return this.entry.getAttributeValue(attrName);
/*     */   }
/*     */   
/*     */   public boolean hasAttribute(String attrName)
/*     */   {
/*  91 */     return this.entry.hasAttribute(attrName);
/*     */   }
/*     */   
/*     */   public void mapToAttrs(Map<String, Object> mapAttrs)
/*     */   {
/*  96 */     AttributeManager attrMgr = AttributeManager.getInst();
/*     */     
/*  98 */     for (Map.Entry<String, Object> me : mapAttrs.entrySet())
/*     */     {
/* 100 */       String attrName = (String)me.getKey();
/* 101 */       Object v = me.getValue();
/*     */       
/* 103 */       boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
/* 104 */       boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);
/*     */       
/* 106 */       if ((v instanceof String)) {
/* 107 */         ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String)v);
/* 108 */         Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
/* 109 */         this.entry.addAttribute(a);
/* 110 */       } else if ((v instanceof String[])) {
/* 111 */         String[] sa = (String[])v;
/* 112 */         ASN1OctetString[] values = new ASN1OctetString[sa.length];
/* 113 */         for (int i = 0; i < sa.length; i++) {
/* 114 */           values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
/*     */         }
/* 116 */         Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
/* 117 */         this.entry.addAttribute(a);
/* 118 */       } else if ((v instanceof Collection)) {
/* 119 */         Collection c = (Collection)v;
/* 120 */         ASN1OctetString[] values = new ASN1OctetString[c.size()];
/* 121 */         int i = 0;
/* 122 */         for (Object o : c) {
/* 123 */           values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
/* 124 */           i++;
/*     */         }
/* 126 */         Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
/* 127 */         this.entry.addAttribute(a);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void setDN(String dn)
/*     */   {
/* 134 */     this.entry.setDN(dn);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/ldap/unboundid/UBIDMutableEntry.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */